<template>
<view class="page">
	<template v-if="isLogin">
		<template v-if="loadingState.default">
			<loading :loadingState="loadingState"></loading>
		</template>
		<template v-else>
			<view class="body">  
				<!-- 2 项目管理员 3 作业人员-->
				<template v-if="auth">
					<template v-if="auth.alltype.indexOf(2)!=-1||auth.alltype.indexOf(3)!=-1&&detail.project.preject_type!=5">
						<view class="img-tab row-1">
							<navigator open-type="navigate" hover-class="none" :url="'/package_project/cy_pro/work/work?pro_name='+detail.project.pname+'&pro_type='+detail.project.project_type+'&pid='+detail.project.id">
								<image :src="img_path+'/wxicon/cy_bt.png'" mode="widthFix"></image>
							</navigator>						 
						</view>
					</template>
				</template>
				
				
				<view class="data-wrap m-b2">
					<view class="hd"><text>项目名称</text></view>
					<view class="con">
						<view class="project-item project-name">
							<view class="label">项目名称：</view>
							<view class="name">{{detail.project.pname}}</view>
						</view> 
						<view class="project-item project-name">
							<view class="label">创建时间：</view>
							<view class="name">{{detail.project.create_time}}</view>
						</view> 
					</view>
				</view>
				 
				<!-- 2 项目管理员 -->
				<template v-if="auth">
					<template v-if="auth.alltype.indexOf(2)!=-1&&detail.project.preject_type!=5"> 
						<view class="data-wrap">
							<view class="hd"><text>添加成员</text></view>
							<view class="con">
								<view class="category-list row-3">
									<navigator open-type="navigate" :url="'/package_project/jc_pro/addMember/addMember?pid='+id" hover-class="none" class="item">
										<view class="icon"><image :src="img_path+'/wxicon/add_worker.png'" mode="widthFix"></image></view>
										<view class="text">添加成员</view>
									</navigator> 
								</view> 
							</view>
						</view>
					</template>
				</template>
				
				<view class="data-wrap">
					<view class="hd"><text>抽样调查数据</text></view>
					<view class="con">
						<template v-if="dataloading.loading">
							<loading :loadingState="dataloading" height="200"></loading>
						</template>
						<template v-else>
							<view class="category-list row-3">
								<navigator open-type="navigate" :url="'/package_project/cy_pro/dataList/dataList?type=all&pid='+detail.project.id+'&pro_type='+detail.project.project_type" hover-class="none" class="item">
									<view class="icon"><image src="@/static/images/jl_pc.png" mode="widthFix"></image></view>
									<view class="text">抽样调查数据</view>
								</navigator>
								<!-- <view class="item">
									<view class="icon"><image src="@/static/images/export.png" mode="widthFix"></image></view>
									<view class="text">导出数据</view>
								</view> -->
								<view class="item" @click="openMap" data-type="jc" data-range="all">
									<view class="icon"><image src="@/static/images/blue_map.png" mode="widthFix"></image></view>
									<view class="text">抽样调查地图</view>
								</view> 
							</view>
							<view class="data-list ">
								<view class="item" v-for="(item,index) in pcinfo" :key="index">
									<view class="label">{{item.name}}</br>{{item.unit}}</view>
									<text class="val">{{item.value}}</text>
								</view>								 
							</view>
						</template>
						
					</view>
				</view>
				
				<!-- <view class="data-wrap">
					<view class="hd"><text>监测月数据</text></view>
					<view class="con">
						<template v-if="dataloading.loading">
							<loading :loadingState="dataloading" height="200"></loading>
						</template>
						<template v-else>
							<view class="category-list row-3">
								<navigator open-type="navigate" hover-class="none" :url="'/package_project/dataList/dataList?pid='+detail.project.id+'&pro_type='+detail.project.project_type" class="item">
									<view class="icon"><image src="@/static/images/jl_pc.png" mode="widthFix"></image></view>
									<view class="text">监测数据</view>
								</navigator>
								<view class="item">
									<view class="icon"><image src="@/static/images/export.png" mode="widthFix"></image></view>
									<view class="text">导出数据</view>
								</view>
								<view class="item">
									<view class="icon"><image src="@/static/images/blue_map.png" mode="widthFix"></image></view>
									<view class="text">监测地图</view>
								</view> 
							</view>
							<view class="data-list ">
								<view class="item" v-for="(item,index) in pcinfo_month" :key="index">
									<view class="label">{{item.name}}</br>{{item.unit}}</view>
									<text class="val">{{item.value}}</text>
								</view>								 
							</view>
						</template>
						
					</view>
				</view> -->
				
				 
				<view v-if="detail.workers.length>0" class="data-wrap">
					<view class="hd"><text>项目成员</text></view>
					<view class="con">
						<view class="detail-wrap">
							<navigator open-type="navigate" hover-class="none" :url="'/package_project/jc_pro/workProjectDetail/workProjectDetail?team_name='+item.realname+'&pid='+detail.project.id+'&pro_type='+detail.project.project_type+'&uid='+item.uid" class="detail-item" v-for="(item,index) in detail.workers" :key="index"> 
								<view class="detail-input">
									<view class="content">
										<view class="val">{{item.realname}}</view> 
									</view>				
									<view class="icon">
										<view class="iconfont f-s68">&#xeb8a;</view>
									</view>	
								</view>			
							</navigator>  
						</view> 
					</view>
				</view>
			</view> 
		</template>
		
	</template> 
	
	   
</view>
</template>

<script> 
import loading from '@/components/loading-more.vue'
import empty from '@/components/empty.vue'
import {router} from '@/common/util.js'

export default{
	name:'demo',
	data(){
		return{ 
			isLogin:false,
			id:'',
			pro_type:'',
			pro_name:'',
			pro_name_1:'',
			userInfo:uni.getStorageSync('userInfo'),
			loadingState: {
				default: true,
				loading: false,
				completed: false
			},
			dataloading:{
				loading:true
			},
			params:{
				type_date:'',
				pid:'',
				union_pid:''
			},
			detail:{},
			pcinfo:[],
			pcinfo_month:[],
			fkinfo:[],
			jlinfo:[],
			img_path:getApp().globalData.web_host,
			auth:null
			
		}
	},
	onShow() {
		// 监听作业提交 更新监测数据
		uni.$on("updatePcinfo", res => {  
			
			if(res){
				if(this.pro_type==1){
					this.getProjectPcinfo({
						pid:this.id,
						type_date:''
					}); 
					this.getProjectFkinfo({
						pid:this.id
					});			
				}else if(this.pro_type==2){   
					this.getProjectPcinfo({
						pid:this.id,
						type_date:''
					});  
				}else if(this.pro_type==3){ 
					this.getProjectPcinfo({
						pid:this.params.union_pid,
						type_date:''
					}); 
					this.getProjectFkinfo({
						pid:this.params.union_pid
					});
					this.getProjectJlinfo();
				}	
			}					
		})		
	},
	
	onHide() {
		 
	},
	async onLoad(params) {   
		this.id=params.pid;
		this.pro_type=params.pro_type; 
		this.params.union_pid=params.union_pid;
		this.isLogin = await this.$loginState('check');
		if(this.isLogin){
			this.getProject();	
			this.getUserOperationAuth();
			
			this.getProjectPcinfo({
				type_date:''
			})
			
		}
	},
	methods:{
		
		// 获取用户权限
		getUserOperationAuth:async function(){
			let res=await this.$api.user_api.getUserInfo({
				ret_type:1
			});   
			if(res.data.ret==0){
				this.auth=res.data.data;
			}
		},
		
		// 获取项目详情
		getProject:async function(){
			let res=await this.$api.pro_api.getProject({
				pid: this.id
			})    
			if(res.data.ret==0){
				this.loadingState.default=false; 
				this.detail=res.data.data;
			}else{
				this.loadingState.default=false;
			}
		},
		
		// 获取监测普查数据概况
		getProjectPcinfo:async function(obj){ 
			// obj  pid 项目id   type_date 是否月数据 1月数据 
			let res=await this.$api.pro_api.getPcinfo({
				pid: this.id,
				uid: this.userInfo.id,
				type_code: 'pc_data', 
				pro_type: this.pro_type,     // 监理不传type
				dataRange: 'all',
				type_date: obj.type_date   // 数据类型 1 月 
			})      
			console.log(res)
			if(res.data.ret==0){ 
				this.dataloading.loading=false; 
				if(obj.type_date==1){ 
					this.pcinfo_month=res.data.data;   // 月数据
				}else{ 
					this.pcinfo=res.data.data;
				}
				
			}else{
				this.loadingState.default=false;
			}
		},
		
		// 获取防控防疫防效数据概况
		getProjectFkinfo:async function(obj){
			// obj pid 监理id
			
			let res=await this.$api.ycj_api.getProjectFkinfo({
				pid: obj.pid,
				uid: this.userInfo.id,
				type_code: 'fk_data', 
				pro_type: this.pro_type==3?'':this.pro_type,     // 监理不传type
				dataRange: 'all', 
			})  
			console.log('pc_data12231',res)
			if(res.data.ret==0){
				this.dataloading.loading=false;
				this.fkinfo=res.data.data;
			}else{
				this.loadingState.default=false;
			}
		}, 
		
		
		// 获取监理数据概况
		
		getProjectJlinfo:async function(){
			let res=await this.$api.ycj_api.getProjectJlinfo({
				pid: this.id,
				uid: this.userInfo.id,
				type_code: 'jl_data', 
				dataRange: 'all',
				// is_app:1
			})   
			console.log('pc_data12231',res)
			if(res.data.ret==0){
				this.dataloading.loading=false;
				this.jlinfo=res.data.data;
			}else{
				this.loadingState.default=false;
			}
		}, 
		
		openMap:function(e){ 
			let type = e.currentTarget.dataset.type; 
			let range= e.currentTarget.dataset.range; 
			router({
				opentype:'navigate',
				url:'/pages/webview/webview',
				params:{
					dataRange: range,
					memberInfo: "0",
					page_type: "map",
					pid: this.id, 
					type: type, 
					uid: this.userInfo.id, 
				}
			})
			
		},
		
		//导出处理
		 
		
		 
		
		
		
	},
	computed:{
		
	},
	components:{
		loading,
		empty
	}
}
</script>

<style lang="less">
	.data-wrap{
		width: 96%;
		margin: 20rpx auto;
		background: #fff;
		border-radius: 10rpx; 
		.hd{
			padding:15rpx 20rpx;
			border-bottom:1rpx solid #ddd;
			text{
				padding-left:20rpx;
				border-left:10rpx solid #f00;
				font-size: 32rpx;
				font-weight: bold;
			}
		}
		.con{ 
		}
	}
	.category-list{
		margin:10rpx 0 0;
	}
	.project-item{
		display: flex;
		padding:20rpx;
		font-size: 32rpx;
		.label{
			flex-shrink: 0;
		}
		.name{
			flex-grow: 2;
		}
	}
	.detail-wrap{ 
	}
	.data-list{
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between; 
		padding-bottom:20rpx;
		margin:0 20rpx;
		border-top:1rpx dashed #ddd;
		.item{ 
			width:22%;
			margin-top: 30rpx;
			font-size:28rpx;
			text-align: center;
			.label{
				height: 90rpx;
				color:#999;
			}
		}
	}
	.img-tab{
		display: flex;
		justify-content: space-between;
		width: 96%;
		margin: 20rpx auto;		
		navigator{  
			image{
				width: 100%;
			}
		}
	}
	.row-1{
		navigator{
			flex-grow: 1;
		}
	}
	.row-2{
		navigator{
			width: 49%;
		}
	}
	.row-3{
		navigator{
			width: 32%;
		}
	}
</style>
